
const nameRegexp = {
    pattern: /^[\u4e00-\u9fa5a-z0-9_]{1,32}$/i,
    message: "1-32位，只允许输入数字、字母、汉字、下划线"
}
// const pwdRegexp = {
//     pattern: /(^(?=.*[a-z])(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,30}$)|(^(?=.*\d)(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,30}$)|(^(?=.*\d)(?=.*[a-z])(?=.*\W)[\da-zA-Z\W]{8,30}$)|(^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z\W]{8,30}$)/,
//     message: "8-30位,数字、大、小写、特殊字符(!、$、#、%),三种及以上组合"
// }
const pwdRegexp = (start, end) => {
    let str = `(^(?=.*[a-z])(?=.*[A-Z])(?=.*\\W)[\\da-zA-Z\\W]{${start},${end}}$)|(^(?=.*\\d)(?=.*[A-Z])(?=.*\\W)[\\da-zA-Z\\W]{${start},${end}}$)|(^(?=.*\\d)(?=.*[a-z])(?=.*\\W)[\\da-zA-Z\\W]{${start},${end}}$)|(^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[\\da-zA-Z\\W]{${start},${end}}$)`;
    let pattern = new RegExp(str);
    let message = `密码为${start}-${end}位,数字、大、小写、特殊字符(!、$、#、%),三种及以上组合`
    return { pattern, message };
}
const cloudPwdRegexp = (start, end) => { // 四大平台密码校验
    let s = "\\u0028\\u0029\\u0060\\u007e\\u0021\\u0040\\u0023\\u0024\\u0025\\u005e\\u0026\\u002a\\u005f\\u002d\\u002b\\u003d\\u007c\\u007b\\u007d\\u005b\\u005d\\u003a\\u003b\\u0027\\u003c\\u003e\\u002c\\u002e\\u003f\\u002f";
    let str = `(^(?=.*[a-z])(?=.*[A-Z])(?=.*[${s}])[\\da-zA-Z${s}]{${start},${end}}$)|(^(?=.*\\d)(?=.*[A-Z])(?=.*[${s}])[\\da-zA-Z${s}]{${start},${end}}$)|(^(?=.*\\d)(?=.*[a-z])(?=.*[${s}])[\\da-zA-Z${s}]{${start},${end}}$)|(^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[\\da-zA-Z${s}]{${start},${end}}$)`;
    let pattern = new RegExp(str);
    let message = `密码为${start}-${end}位,数字、大、小写、特殊字符()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/,三种及以上组合`
    return { pattern, message };
}
const bmsPwdRegexp = (num) => {
    let str = `^(?=.*[0-9][\\da-zA-Z]*)(?=.*[A-Z][\\da-zA-Z]*)(?=.*[a-z][\\da-zA-Z]*)[\\da-zA-Z]{${8}}$`
    let pattern = new RegExp(str);
    let message = `密码为${num}位,数字、大、小写字母组合`
    return { pattern, message };
}
const codeRegexp = {
    pattern: /^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/,
    message: "输入字段不合法"
}
const portRegexp = {
    pattern: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,
    message: "输入端口不合法"
}
const vncPortRegexp = {
    pattern: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,
    message: "端口范围为0-65535"
}
const rangePortRegexp = {
    pattern: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])\-([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,
    message: "端口范围输入不规范",
}
const ipRegexp = {
    pattern: /^(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)(\/(\d|[1-2]\d|3[0-2]))?$/,
    message: "输入ip不合法"
}
const obsIpRegexp = {
    pattern: /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+?$/,
    message: "输入ip不合法"
}

const phoneRegexp = {
    pattern: /^1[3456789]\d{9}$/,
    message: "输入手机号不合法"
}

const emailRegexp = {
    pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
    message: "输入邮箱不合法"
}

const remarksRegexp = {
    pattern: /^[\u4e00-\u9fffa-zA-Z]{1,50}$/,
    message: "字符超出"
}
const urlRegexp = {
    pattern: '^((https|http|ftp|rtsp|mms)?://)'
        + '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?' //ftp的user@ 
        + '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184 
        + '|' // 允许IP和DOMAIN（域名） 
        + '([0-9a-z_!~*\'()-]+.)*' // 域名- www. 
        + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名 
        + '[a-z]{2,6})' // first level domain- .com or .museum 
        + '(:[0-9]{1,4})?' // 端口- :80 
        + '((/?)|' // a slash isn't required if there is no file name 
        + '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$',
    message: "输入url不合法",
}

const keyRegexp = (start, end) => {
    let pattern = new RegExp(`^[a-zA-Z\\d]{${start},${end}}$`);
    let message = `${start}-${end}位，只允许输入大小写字母、数字`;
    return { pattern, message };
}

const netNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\u4e00-\\u9fa5]{0,${num}}$`);
    let message = `只允许输入数字、字母、汉字、下划线，最多输入${num}个字符`;
    return { pattern, message };
}

const oseasyNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\-\\(\\)\\u4e00-\\u9fa5]{0,${num}}$`);
    let message = `只允许输入数字、字母、汉字、减号、英文小括号、下划线，最多输入${num}个字符`;
    return { pattern, message };
}

const ntcNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\-\\_\\u4e00-\\u9fa5]{0,${num}}$`);
    let message = `只允许输入数字、字母、汉字、下划线及中划线，最多输入${num}个字符`;
    return { pattern, message };
}

const processNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\-\\_\\u4e00-\\u9fa5]{0,${num}}$`);
    let message = `只允许输入汉字、字母、数字、中划线及下划线，最多输入${num}个字符`;
    return { pattern, message };
}
const fileRegexp = {
    pattern: /^[\\|\/]/,
    message: "目录名不能以\/ 或 \ 开头"
}
const fileContinuousRegexp = {
    pattern: /\/{2,}/,
    message: "目录名不允许出现连续的 /"
}
const file3Regexp = {
    pattern: /\.\./,
    message: "目录名中不允许出现名为 .. 的子目录"
}
const file1Regexp = {
    pattern: /[\:|\*|\?|\"|\<|\>|\||\|\\"]{1,}/,
    message: "目录不能包含以下字符\:*?\"<>|"
}
const obsCreate1Regexp = {
    pattern: /\.\.|\.\-/,
    message: "目录名不允许出现连续的(.)和(.-)"
}
const obsCreate2Regexp = {
    pattern: /[A-Z]|_/,
    message: "不能包含大写字母或下划线"
}
const obsemjioRegexp = {
    pattern: /^\\u0000-\\uFFFF/,
    message: "目前请使用UTF-8 字符"
}
const azRegexp = (start, end) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\-\\.\\u4e00-\\u9fa5]{${start},${end}}$`);
    let message = `${start}-${end}位，只允许输入数字、字母、汉字、特殊字符(._-)`;
    return { pattern, message };
}

const cookieNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d]{0,${num}}$`);
    let message = `只允许输入数字、字母，最多输入${num}个字符`;
    return { pattern, message };
}
const cookieOeasyNameRegexp = (start, end) => {
    let pattern = new RegExp(`^[a-zA-Z][a-zA-Z\\d\\_]{${start - 1},${end - 1}}$`);
    let message = `以字母开头，只允许输入数字、字母、下划线，长度为${start}~${end}个字符`;
    return { pattern, message };
}
const orgCodeRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_]{0,${num}}$`);
    let message = `只允许输入数字、字母、下划线，最多输入${num}个字符`;
    return { pattern, message };
}
const macRegexp = {
    pattern: /((([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}/gi,
    message: "输入mac地址不合法"
}
const aliNameRegexp = (start, end) => {
    let pattern = new RegExp(`^(?!(http:\/\/|https:\/\/))[a-zA-Z][a-zA-Z\\d\\-\\_.]{${start - 1},${end - 1}}$`);
    let message = `长度为${start}~${end}个字符，必须以英文字母开头，可包含数字、点号、下划线及中划线，不能以http://或https://开头`;
    return { pattern, message };
};
const aliSubNameRegexp = (start, end) => {
    let pattern = new RegExp(`^(?!(http:\/\/|https:\/\/))[a-zA-Z][\\s\\S]{${start - 1},${end - 1}}$`);
    let message = `长度为${start}~${end}个字符，必须以英文字母开头，不能以http://或https://开头`;
    return { pattern, message };
};
const VMWARENameRegexp = (num) => {
    let pattern = new RegExp(`^[\\u0021-\\u007E]{0,${num}}$`);
    let message = `不允许输入汉字字符，最多输入${num}个汉字`;
    return { pattern, message };
}
const mySqlTempNameRegexp = ({ getFieldError }, length1 = 8, length2 = 64) => {
    return {
        //   validateTrigger: "onBlur",
        validator: (rules, value) => {
            if (value !== undefined && value !== '') {
                let pattern = /^[a-zA-Z][a-zA-Z0-9\_\-]*$/;
                let patternCh = /[\u4E00-\u9FA5]/g
                if (!pattern.test(value)) {
                    return Promise.reject("以字母开头，只能包含字母、数字、中划线、下划线！");
                } else if (patternCh.test(value)) {
                    return Promise.reject("不允许输入中文");
                } else if (value.length < length1) {
                    return Promise.reject(`长度不能小于${length1}位！`);
                } else if (value.length > length2) {
                    return Promise.reject(`长度不能大于${length2}位！`);
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`名称不能为空`);
            }
        }
    }
}
const mySqlAccountNameRegexp = ({ getFieldError }, length1 = 2, length2 = 16) => {

    // return { pattern, message };

    return {
        //   validateTrigger: "onBlur",
        validator: (rules, value) => {
            if (value) {
                let pattern = /^[a-zA-Z][a-zA-Z0-9\_\-]*$/;
                let patternCh = /[\u4E00-\u9FA5]/g
                let list = ['root', 'os_admin', 'monitor_admin'];
                if (list.includes(value)) {
                    return Promise.reject("名称不合法，请重新输入。");
                } else if (!pattern.test(value)) {
                    return Promise.reject("必须以字母开头，由字母、数字、中划线或下划线组成。");
                } else if (patternCh.test(value)) {
                    return Promise.reject("不允许输入中文");
                } else if (value.length < length1) {
                    return Promise.reject(`长度不能小于${length1}位`);
                } else if (value.length > length2) {
                    return Promise.reject(`长度不能大于${length2}位`);
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`名称不能为空`);
            }
        }
    }
}

const backupInstanceRegexp = ({ getFieldError }, length1 = 4, length2 = 32) => {
    return {
        //   validateTrigger: "onBlur",
        validator: (rules, value) => {
            if (value !== undefined && value !== '') {
                let pattern = /^[a-zA-Z][a-zA-Z0-9\_\-]*$/;
                if (!pattern.test(value)) {
                    return Promise.reject("请以字母开头，只能包含字母、数字、中划线、下划线！");
                } else if (value.length < length1) {
                    return Promise.reject(`长度不能小于${length1}位`);
                } else if (value.length > length2) {
                    return Promise.reject(`长度不能大于${length2}位`);
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`名称不能为空！`);
            }
        }
    }
}
const clearNoNum = (value) => {
    value = value.replace(/[^\d.]/g, "");//清除“数字”和“.”以外的字符
    value = value.replace(/^\./g, "");//验证第一个字符是数字而不是.
    value = value.replace(/\.{2,}/g, ".");//只保留第一个. 清除多余的.
    value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    return value
}

const nasNameRegexp = (start, end) => {
    let pattern = new RegExp(`^[a-zA-Z\\u4e00-\\u9fa5][a-zA-Z\\u4e00-\\u9fa5\\d\\-\\_]{${start - 1},${end - 1}}$`);
    let message = `长度为${start}-${end}字符，以大小写字母或中文开头，可包含数字，“_”或“-”。`;
    return { pattern, message };
};

const mySqlParamsSettingRegexp = ({ getFieldError }, min = 0, max = 100, type) => {
    if (type !== 'integer') {
        return {
            validator: (rules, value) => {
                return Promise.resolve();
            }
        }
    }
    return {
        validator: (rules, value) => {
            if (value !== undefined || value === '') {
                if (!((value > min && value < max) || value === min - 0 || value === max - 0)) {
                    return Promise.reject(`请输入${min}-${max}之间的整数`);
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`请输入${min}-${max}之间的整数`);
            }
        }
    }

}
const ecsBackupsNameRegexp = (min = 1, max = 32) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\u4e00-\\u9fa5]{${min},${max}}$`);
    let message = `只能输入数字、字母、汉字和下划线`;
    return { pattern, message };
};

const redisPwdRegexp = (start, end) => {
    let s = "\\u0028\\u0029\\u0060\\u007e\\u0021\\u0040\\u0023\\u0024\\u0025\\u005e\\u0026\\u002a\\u005f\\u002d\\u002b\\u003d\\u007c\\u007b\\u007d\\u005b\\u005d\\u003a\\u003b\\u0027\\u003c\\u003e\\u002c\\u002e\\u003f"
    let str = `(^(?!\/)(?=.*\\d)(?=.*[A-Z])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*\\d)(?=.*[a-z])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*\\d)(?=.*[${s}])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*[a-z])(?=.*[A-Z])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*[a-z])(?=.*[${s}])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*[a-z])(?=.*\\d)[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*[A-Z])(?=.*[a-z])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*[A-Z])(?=.*\\d)[\\da-zA-Z\\u002f${s}]{${start},${end}}$)|(^(?!\/)(?=.*[A-Z])(?=.*[${s}])[\\da-zA-Z\\u002f${s}]{${start},${end}}$)`;
    let pattern = new RegExp(str);
    let message = '输入内容不合法';
    let tip = `密码规则为${start}-${end}个字符，至少包含小写字母、大写字母、数字和字符 ()\`~!@#$%^&*-+=_|{}[]:;<>,.?/ 中的2种，不能以"/"开头`
    return { pattern, message, tip };
}
const asGroupNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\.\\-\\u4e00-\\u9fa5]{0,${num}}$`);
    let message = `只允许输入数字、字母、汉字、下划线、分隔符-和小数点，最多输入${num}个字符`;
    return { pattern, message };
}
const timedJobNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\u4e00-\\u9fa5]{0,${num}}$`);
    let message = `只允许输入数字、字母、汉字、下划线，最多输入${num}个字符`;
    return { pattern, message };
}

const vncPasswordRegexp = (num) => {
    const start = 8;
    const end = 8;
    let s = "\\u0028\\u0029\\u0060\\u007e\\u0021\\u0040\\u0023\\u0024\\u0025\\u005e\\u0026\\u002a\\u005f\\u002d\\u002b\\u003d\\u007c\\u007b\\u007d\\u005b\\u005d\\u003a\\u003b\\u0027\\u003c\\u003e\\u002c\\u002e\\u003f\\u002f\\u2002\\u2003\\u00a0";
    let str = `(^(?=.*[a-z])(?=.*[A-Z])(?=.*[${s}])[\\da-zA-Z${s}]{${start},${end}}$)
                |(^(?=.*\\d)(?=.*[A-Z])(?=.*[${s}])[\\da-zA-Z${s}]{${start},${end}}$)
                |(^(?=.*\\d)(?=.*[a-z])(?=.*[${s}])[\\da-zA-Z${s}]{${start},${end}}$)`;
    let pattern = new RegExp(str);
    let message = `密码必须为${end}位,至少包含一个特殊字符()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/,以及至少包含小写字母，大写字母，数字中的两种`;
    return { pattern, message };
}

const ipmiNameRegexp = (num) => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\-]{0,${num}}$`);
    let message = `只允许输入数字、字母、-，最多输入${num}个字符`;
    return { pattern, message };
}
const numberWayRegexp = (num) => {
    let pattern = new RegExp(`^[\\d]{0,${num}}$`);
    let message = `只允许输入数字,最多输入${num}个数字`;
    return { pattern, message };
}
const DRDSAccountNameRegexp = ({ getFieldError }, length1 = 4, length2 = 32) => {
    return {
        validator: (rules, value) => {
            if (value) {
                let pattern = /^[A-Za-z0-9\_\-]*$/;
                let pattern2 = /[A-Za-z0-9]+/;
                let list = ['root', 'admin', 'os_admin', 'monitor_admin'];
                if (list.includes(value)) {
                    return Promise.reject("输入内容不合法");
                } else if (!pattern.test(value)) {
                    return Promise.reject("输入内容不合法");
                } else if (!pattern2.test(value)) {
                    return Promise.reject("至少包含1个字母或数字");
                } else if (value.length < length1) {
                    return Promise.reject(`长度不能小于${length1}位`);
                } else if (value.length > length2) {
                    return Promise.reject(`长度不能超过${length2}位`);
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`账号不能为空`);
            }
        }
    }
}

const DRDSAccountPWDRegexp = ({ getFieldError }, length1 = 8, length2 = 30) => {
    return {
        validator: (rules, value) => {
            if (value) {
                let pattern = cloudPwdRegexp(length1, length2).pattern;
                let pattern1 = /^\//;
                if (pattern1.test(value)) {
                    return Promise.reject("输入内容不合法");
                } else if (value.length < length1) {
                    return Promise.reject(`长度不能小于${length1}位`);
                } else if (value.length > length2) {
                    return Promise.reject(`长度不能超过${length2}位`);
                } else if (!pattern.test(value)) {
                    return Promise.reject("输入内容不合法");
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`密码不能为空`);
            }
        }
    }
}

const DRDSDatabaseNameRegexp = (length1 = 2, length2 = 64) => {
    return {
        validator: (rules, value) => {
            if (value) {
                let pattern = /(?!^\_+$)(?!^\-+$)(?!^[\_\-]+$)^[a-zA-Z0-9\_\-]+$/;
                let pattern2 = /^[a-zA-Z]/;
                if (!pattern2.test(value)) {
                    return Promise.reject("请以字母开头");
                }else if (!pattern.test(value)) {
                    return Promise.reject("输入内容不合法");
                } else if (value.length < length1) {
                    return Promise.reject(`长度不能小于${length1}位`);
                } else if (value.length > length2) {
                    return Promise.reject(`长度不能超过${length2}位`);
                } else {
                    return Promise.resolve();
                }
            } else {
                return Promise.reject(`名称不能为空`);
            }
        }
    }
}

const brandRegexp = () => {
    return {
        validator: (rules, value) => {
            if (value) {
                let whiteList = ['华为','华三','浪潮','长城','泰山','中兴'];
                
                if (whiteList.indexOf(value) >= 0) {
                    return Promise.resolve();
                }  else {
                    return Promise.reject("品牌输入有误，支持的服务器品牌有华为、华三、浪潮、长城、泰山、中兴");
                }
            }
        }
    }
}

const rootDeviceRegexp = () => {
    return {
        validator: (rules, value) => {
            if (value) {
                let whiteList = ['/dev/sda','/dev/sdm','/dev/sdw'];
                
                if (whiteList.indexOf(value) >= 0) {
                    return Promise.resolve();
                }  else {
                    return Promise.reject("目前仅支持 /dev/sda 、 /dev/sdm 或者/dev/sdw");
                }
            }
        }
    }
}

const tableNameRegexp = (list) => {
    return {
        validator: (rules, value) => {
            if (value) {
                let pattern = /^[a-zA-Z]/;
                if (!pattern.test(value)) {
                    return Promise.reject("请以字母开头");
                }else if (value.length > 64) {
                    return Promise.reject("超出不支持输入");
                }else if(list.indexOf(value) >=0 ){
                    return Promise.reject("与现有表名重复");
                }else {
                    return Promise.resolve();
                }
            }else{
                return Promise.reject("请输入表名");
            }
        }
    }
}

const columnNameRegexp = (list,message="列名不能重复") => {
    const check = value => list.reduce((pre,cur)=>cur === value ? ++pre : pre, 0 );
    return {
        validator: (rules, value) => {
            // console.log('list',list)
            // console.log('value',value)
            if (value) {
                if(check(value) > 1 ){
                    return Promise.reject(message);
                }else {
                    return Promise.resolve();
                }
            }
        },
        message,
    }
}

const startNameMustLetterRegexp = () => {
    return {
        validator: (rules, value) => {
            if (value) {
                let pattern = /^[a-zA-Z]/;
                if (!pattern.test(value)) {
                    return Promise.reject("请以字母开头");
                }else {
                    return Promise.resolve();
                }
        }
    },
    message:'请以字母开头',
}
}

const indexColumnRegexp = (list) => {
    const check = value => list.reduce((pre,cur)=>cur === value ? ++pre : pre, 0 );
    return {
        validator: (rules, value) => {
            // console.log('list',list)
            console.log('value',value)
            if (value) {
                if(check(value) > 1 ){
                    return Promise.reject("所选列信息不能重复");
                }else {
                    return Promise.resolve();
                }
            }else{
                return Promise.resolve();
            }
        },
        message:'所选列信息不能重复',
    }
}

const numberRegexp = () => {
    let pattern = new RegExp(`^[0-9]*$`);
    let message = `只允许输入数字`;
    return { pattern, message };
}

const uniqueIdentificationRegexp = (num) => {
 let pattern = new RegExp(`^[a-zA-Z][a-zA-Z0-9\_-]{0,${num}}$`);
    let message = `只允许字母开头，输入数字、字母、下划线,横线组合，最多输入${num}个字符`;
    return { pattern, message };
}

const commonTextRegexp = (start=0, end=100) => {
    let s = "\\u0028\\u0029\\u0060\\u007e\\u0021\\u0040\\u0023\\u0024\\u0025\\u005e\\u0026\\u002a\\u005f\\u002d\\u002b\\u003d\\u007c\\u007b\\u007d\\u005b\\u005d\\u003a\\u003b\\u0027\\u003c\\u003e\\u002c\\u002e\\u003f\\u002f";
    let pattern = new RegExp(`^[a-zA-Z\\d\\s\\u4e00-\\u9fa5${s}]{${start},${end}}$`);
    let message = `只允许包含${start}-${end}位中文、英文、数字及常用字符`;
    return { pattern, message };
}

const commonNameRegexp = (start=1, end=100, fieldName="名称") => {
    let s = "\\u0028\\u0029\\u0060\\u007e\\u0021\\u0040\\u0023\\u0024\\u0025\\u005e\\u0026\\u002a\\u005f\\u002d\\u002b\\u003d\\u007c\\u007b\\u007d\\u005b\\u005d\\u003a\\u003b\\u0027\\u003c\\u003e\\u002c\\u002e\\u003f\\u002f";
    let pattern = new RegExp(`^[a-zA-Z\\d\\u4e00-\\u9fa5${s}]{${start},${end}}$`);
    let message = `${fieldName}不能为空,只允许包含${start}-${end}位中文、英文、数字及常用字符`;
    return { pattern, message };
}

const commonCodeRegexp = (start=1, end=100, fieldName="唯一标识") => {
    let pattern = new RegExp(`^[a-zA-Z\\d\\_\\-\\.]{${start},${end}}$`);
    let message = `${fieldName}不能为空,只允许包含${start}-${end}位英文、数字、下划线、短横线和点`;
    return { pattern, message };
}

const regexpUtil = {
    nameRegexp,
    pwdRegexp,
    cloudPwdRegexp,
    bmsPwdRegexp,
    portRegexp,
    rangePortRegexp,
    ipRegexp,
    obsIpRegexp,
    phoneRegexp,
    emailRegexp,
    remarksRegexp,
    urlRegexp,
    keyRegexp,
    netNameRegexp,
    ntcNameRegexp,
    processNameRegexp,
    codeRegexp,
    fileRegexp,
    fileContinuousRegexp,
    file3Regexp,
    file1Regexp,
    obsCreate1Regexp,
    obsCreate2Regexp,
    obsemjioRegexp,
    azRegexp,
    orgCodeRegexp,
    cookieNameRegexp,
    cookieOeasyNameRegexp,
    macRegexp,
    aliNameRegexp,
    aliSubNameRegexp,
    VMWARENameRegexp,
    mySqlTempNameRegexp,
    mySqlAccountNameRegexp,
    backupInstanceRegexp,
    mySqlParamsSettingRegexp,
    clearNoNum,
    nasNameRegexp,
    ecsBackupsNameRegexp,
    redisPwdRegexp,
    asGroupNameRegexp,
    timedJobNameRegexp,
    oseasyNameRegexp,
    vncPasswordRegexp,
    numberWayRegexp,
    DRDSAccountNameRegexp,
    DRDSAccountPWDRegexp,
    DRDSDatabaseNameRegexp,
    brandRegexp,
    rootDeviceRegexp,
    tableNameRegexp,
    vncPortRegexp,
    ipmiNameRegexp,
    columnNameRegexp,
    numberRegexp,
    indexColumnRegexp,
    startNameMustLetterRegexp,
    uniqueIdentificationRegexp,
    commonTextRegexp,
    commonNameRegexp,
    commonCodeRegexp
}

export default regexpUtil;